require.config({
	paths: {
		"jquery" : "jquery-1.11.3",
		"common" : "common",
		//"cityselect" : "jquery.cityselect"
		"cookie" : "cookie"
	}
});


require(["jquery","common","cookie"],function($,common,cookie){
	$(".header").load("header.html",function(){common.fn();});
	$(".footer").load("footer.html",function(){common.fn();});
	$(".side").load("side.html",function(){common.fn();});
		/*选择送货地区*/
//		cityselect.fn($(".city").citySelect({
//			prov:"湖南", 
//			city:"长沙",
//			dist:"岳麓区",
//			nodata:"none"
//		}))
//		$(".city").citySelect({
//			prov:"湖南", 
//			city:"长沙",
//			dist:"岳麓区",
//			nodata:"none"
//		});
		
		
		/*数量减少和增加按钮*/
		$(".lessBtn").click(function(){
			var num = parseInt($("#chNum").val());
			if(num == 1){
				$(".caution").text("最少购买一件").animate({"opacity":"1"},1000).animate({"opacity":"0"},1000);
			}else {
				num --;
			}
			$("#chNum").val(num.toString());
		});
		
		$(".addBtn").click(function(){
			var num = parseInt($("#chNum").val());
			if(num == 6){
				$(".caution").text("限购6件").animate({"opacity":"1"},1000).animate({"opacity":"0"},1000);
			}else {
				num ++;
			}
			$("#chNum").val(num.toString());
		});
		
		/*加入购物车操作*/
		/*function addHtml(){
			product = eval("(" + getCookie("product_1") + ")");
			var text_html='';
			var totalMoney=0;
			$(".cartCon").html("");
			text_html+='<tr><td>'+product.name+'</td><td>'+product.price+'</td><td> '+product.num+' ';
			text_html+='</td><td>￥'+(product.price*product.num)+'</td></tr>';
			totalMoney+=product.price*product.num;
			$(".totalMoney").text(totalMoney);
			$(".cartCon").append(text_html);
			
			$(".iNum").text(product.num);
			$(".cartNum").text(product.num);
		}*/
		
		
		
		$(".addCart").each(function(){	
			product = eval("(" + getCookie("product_1") + ")");
			if(product){
				this.num = product.num;
			}else{
				this.num = 0;
			}			
			$(".addCart").click(function(){	
				var addNum = parseInt($("#chNum").val());
				this.num += addNum;
				var id = $("#hid").val();
				var proName = $(".goodsRight h2").text();
				var str = $(".sp2").text();
				var proPrice = parseFloat(str.substr(1,str.length));
				var proSrc = $(".images-cover img").attr("src");
				var cookieValue = "{id:" + id + ',name:"'+ proName+ '",price:'+proPrice+ ",num:" + this.num + ",src:'"+ proSrc+"'}";
				var cookieKey = "product_" + id;
				setCookie(cookieKey,cookieValue,7);			
				product = eval("(" + getCookie("product_1") + ")");
				//alert(product.src);
				/*判断购物车中有无商品*/
				product = eval("(" + getCookie("product_1") + ")");
				if(product){
					$(".noneCart").hide();
					$(".haveCart").show();
					function addHtml(){
						product = eval("(" + getCookie("product_1") + ")");
						var text_html='';
						var totalMoney=0;
						$(".cartCon").html("");
						text_html+='<tr><td>'+product.name+'</td><td>'+product.price+'</td><td> '+product.num+' ';
						text_html+='</td><td>￥'+(product.price*product.num)+'</td></tr>';
						totalMoney+=product.price*product.num;
						$(".totalMoney").text(totalMoney);
						$(".cartCon").append(text_html);
						
						$(".iNum").text(product.num);
						$(".cartNum").text(product.num);						
					}
					addHtml();
				}else {
					$(".noneCart").show();
					$(".haveCart").hide();
				}											
			});
		});
});	
